<?php

//Parametros
include "include/load.php";
include "include/legendastv.php";
include "include/arq.php";

$user = "xixiba";
$pass = "blabla";
$idioma = 1; // 1 = Brazilian Portuguese, 2 = English
$extensions = array('mkv', 'avi');
$dir = "/volume1/video/Seriados/House/";

// Get filenames
$files = dirList($dir, $extensions);

// Login into the site and get cookies
$bolachinha = loga($user, $pass);

foreach($files as $documento) {

  // Search for the subtitle id
  $codigo_legenda = procura($documento, $idioma, $bolachinha);

  if ($codigo_legenda !== 0) {
    // Download subtitle
    $arquivo_compactado = baixarlegenda($documento, $codigo_legenda, $bolachinha);
    if (preg_match("/rar/", $arquivo_compactado))  file_put_contents($documento.".rar", $arquivo_compactado);
    elseif (preg_match("/zip/", $arquivo_compactado))  file_put_contents($documento.".zip", $arquivo_compactado);
  }
}

?>
